<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script>
      class CookieUtil {
        static get(name) {
          let cookieName = `${encodeURIComponent(name)}=`,
            cookieStart = document.cookie.indexOf(cookieName),
            cookieValue = null

          if (cookieStart > -1) {
            let cookieEnd = document.cookie.indexOf(';', cookieStart)
            if (cookieEnd == -1) {
              cookieEnd = document.cookie.length
            }
            cookieValue = decodeURIComponent(
              document.cookie.substring(
                cookieStart + cookieName.length,
                cookieEnd
              )
            )
          }
          return cookieValue
        }

        static set(name, value, expiresOrMaxAge, path, domain, secure) {
          let cookieText = `${encodeURIComponent(name)}=${encodeURIComponent(
            value
          )}`

          if (expiresOrMaxAge instanceof Date) {
            cookieText += `; expires=${expiresOrMaxAge.toGMTString()}`
          } else if (typeof expiresOrMaxAge === 'number') {
            cookieText += `; max-age=${expiresOrMaxAge}`
          }

          if (path) cookieText += `; path=${path}`

          if (domain) cookieText += `; domain=${domain}`

          if (secure) cookieText += '; secure'

          document.cookie = cookieText
        }

        static unset(name, path, domain, secure) {
          CookieUtil.set(name, '', new Date(0), path, domain, secure)
        }
      }
    </script>
  </head>
  <body></body>
</html>
